You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

find-dependency

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-dependency

Find the path to the package that will be used by `require`.

1.3.3
latest
npmnpm
Version published
Weekly downloads
68
106.06%
Maintainers
1
Weekly downloads
 
Created
Source

find-dependency

Find the path to the package that will be used by require.

const findDependency = require('find-dependency');

// Search current directory, all parent directories, and all $NODE_PATH directories.
const packagePath = findDependency('foo', process.cwd());

If only the import path is given, process.cwd() is used.

You can also skip looking for a global installation.

findDependency('foo', {
  // Both are optional.
  skipGlobal: true,
  cwd: process.cwd(),
})

How it works

When you call findDependency('foo', __dirname):

  • Check if __dirname/node_modules/foo is a directory
  • Check if __dirname/../node_modules/foo is a directory
  • Continue adding .. until the home directory is checked
  • Check every directory in process.env.NODE_PATH (eg: global_path/foo)
  • At any point, if the checked path exists, return it

This simulates how require resolves the package path, before checking the main field of its package.json file.

New in v1.1.0: No dependencies, and symlinks are followed.

FAQs

Package last updated on 19 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.